//
//  LSOldPeopleDataCollectionViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/1/7.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSOldPeopleDataCollectionViewController.h"
#import "LSInfoCollectTableViewCell.h"
#import "LSDatePickViewController.h"
#import "LSInfoSelectController.h"
#import "LSMultipleSelectView.h"
#import "TimeUtils.h"
#import "NZKTextView.h"

#define FontSize 14

@interface LSOldPeopleDataCollectionViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UITextViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *contentArray;
@property (nonatomic, strong) NSArray *familyinfoEntitiesContentArray;
@property (nonatomic, assign) BOOL bodyCondition_isShiNeng;
@property (nonatomic, strong) NSArray *contentArray_isShiNeng;
@property (nonatomic, assign) int OldPeopleFamilyDataCount;
@property (nonatomic, strong) NSMutableArray *OldPeopleFamilyDataArrayM;
@property (nonatomic, strong) NSMutableArray *OldPeopleFamilyDataTFsArrayM;
@property (nonatomic, strong) UIView *tableViewFooterView;
@property (nonatomic, strong) NSDictionary *downSelectDict;
@property (nonatomic, strong) NSArray *pickerDataArray;
@property (nonatomic, assign) BOOL isCheckedBefore;
@property (nonatomic, assign) BOOL isHaveDian;

@property (nonatomic, strong) UITextField *nameTF;//姓名(Y)
@property (nonatomic, strong) UITextField *cardNoTF;//身份证号(Y)
@property (nonatomic, strong) UITextField *sexTF;//性别(Y)
@property (nonatomic, strong) UITextField *birthdayTF;//生日(Y)
@property (nonatomic, strong) UITextField *nationTF;//民族(Y)
@property (nonatomic, strong) UITextField *regAdTF;//原户籍地(Y)
@property (nonatomic, strong) NZKTextView *domicileAdrTV;//原户籍地地址(Y)
@property (nonatomic, strong) UITextField *nowAdTF;//现住地(Y)
@property (nonatomic, strong) NZKTextView *locationAdrTV;//现所在地区名称(Y)
@property (nonatomic, strong) UITextField *phoneTF;//联系电话(Y)
@property (nonatomic, strong) UITextField *incomeConditonTF;//收入情况(Y)
@property (nonatomic, strong) UITextField *bankCardnoTF;//银行卡号
@property (nonatomic, strong) UITextField *medicalTypeTF;//医保类型(Y)
@property (nonatomic, strong) UITextField *medicalCardnoTF;//医疗卡号
@property (nonatomic, strong) UITextField *socialCardnoTF;//社保账号
@property (nonatomic, strong) UITextField *bodyConditionTF;//身体状况(Y)
@property (nonatomic, strong) UITextField *disablestandTF;//失能标准
@property (nonatomic, strong) UITextField *disablestand1TF;//失能等级
@property (nonatomic, strong) UITextField *serviceNeedsTF;//服务需求(Y)
@property (nonatomic, strong) UITextField *survivalstateTF;//存活状态(Y)
@property (nonatomic, strong) UITextField *basicLivingTF;//是否低保(Y)
@property (nonatomic, strong) NZKTextView *remarkTV;//备注

@property (nonatomic, strong) NSArray *sexTFArray;
@property (nonatomic, strong) NSArray *nationTFArray;
@property (nonatomic, strong) NSArray *medicalTypeTFArray;
@property (nonatomic, strong) NSArray *bodyConditionTFArray;
@property (nonatomic, strong) NSArray *disablestandTFArray;
@property (nonatomic, strong) NSArray *disablestand1TFArray;
@property (nonatomic, strong) NSArray *serviceNeedsTFArray;
@property (nonatomic, strong) NSArray *survivalstateTFArray;
@property (nonatomic, strong) NSArray *basicLivingTFArray;
@property (nonatomic, strong) NSArray *relationTFArray;
@property (nonatomic, strong) NSArray *emergencyContactTFArray;
@end

static NSString *OldPeopleFoundationDataCollectCellID = @"OldPeopleFoundationDataCollectCellID";

@implementation LSOldPeopleDataCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    self.isCheckedBefore = false;
    self.isHaveDian = false;
    [self loadKeyValues];
    if ([ValidateUtils validateNull:self.displayDataDict[@"bodyCondition"]].integerValue == 3) {
        self.bodyCondition_isShiNeng = true;
    } else {
        self.bodyCondition_isShiNeng = false;
    }
    if (self.isCheck) {
        self.isCheckedBefore = true;
        NSArray *familyinfoEntitiesArray = self.displayDataDict[@"familyinfoEntities"];
        if (![familyinfoEntitiesArray isKindOfClass:[NSNull class]] && familyinfoEntitiesArray && familyinfoEntitiesArray.count > 0) {
            self.OldPeopleFamilyDataCount = (int)familyinfoEntitiesArray.count;
            for (int i = 0; i < self.OldPeopleFamilyDataCount; i++) {
                [self addOneSectionOfTextFields];
            }
        } else {
            self.OldPeopleFamilyDataCount = 0;
        }
//        UIButton *editButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 44)];
//        [editButton setTitle:@"编辑" forState:UIControlStateNormal];
//        [editButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
//        editButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
//        [editButton addTarget:self action:@selector(editButtonClick) forControlEvents:UIControlEventTouchUpInside];
//        UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithCustomView:editButton];
//        self.navigationItem.rightBarButtonItem = editItem;
        [self loadData];
        self.title = @"老龄人员基础信息详情";
    } else {
        self.OldPeopleFamilyDataCount = 0;
        self.title = @"老龄人员基础信息采集";
    }
    [self.view addSubview:self.tableView];
    if (self.isCheck) [self arrangeData];
    if (self.isCheck && self.OldPeopleFamilyDataCount > 0) [self arrangeOldPeopleFamilyData];
}

- (void)getLocationInfoWithCode:(NSString *)code forTextField:(UITextField *)textField {
    if (![code isEqualToString:@""]) {
        NSString *shengCodeString = [NSString stringWithFormat:@"%@0000",[code substringToIndex:2]];
        NSString *shiCodeString = [NSString stringWithFormat:@"%@00",[code substringToIndex:4]];
        NSMutableString *shengshiquString = [[NSMutableString alloc] initWithString:@""];
        for (NSDictionary *shengDict in self.pickerDataArray) {
            if ([shengDict[@"areaId"] isEqualToString:shengCodeString]) {
                [shengshiquString appendString:shengDict[@"areaName"]];
                NSArray *citiesArray = shengDict[@"cities"];
                for (NSDictionary *shiDict in citiesArray) {
                    if ([shiDict[@"areaId"] isEqualToString:shiCodeString]) {
                        [shengshiquString appendFormat:@" %@",shiDict[@"areaName"]];
                        NSArray *quArray = shiDict[@"counties"];
                        for (NSDictionary *quDict in quArray) {
                            if ([quDict[@"areaId"] isEqualToString:code]) {
                                [shengshiquString appendFormat:@" %@",quDict[@"areaName"]];
                                break;
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
        textField.text = shengshiquString.copy;
        textField.placeholder = code;
    }
}

- (NSArray *)pickerDataArray {
    if (!_pickerDataArray) {
        NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"city" ofType:@"json"]];
        _pickerDataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
    }
    return _pickerDataArray;
}

- (void)loadKeyValues {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:OldAgeDictionary param:@{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token]} completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                NSDictionary *dataDict = [responseObject objectForKey:@"data"];
                self.downSelectDict = dataDict;
                [self arrangeDownSelectArrays];
                if (self.isCheck) [self arrangeData];
            } else {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

- (void)arrangeDownSelectArrays {
//    NSArray *DISABLE_LEVALArray = self.downSelectDict[@"DISABLE_LEVAL"];
//    if (DISABLE_LEVALArray && DISABLE_LEVALArray.count > 0) {
//        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
//        for (NSDictionary *dict in DISABLE_LEVALArray) {
//            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
//        }
//        self.disablestand1TFArray = arrayM.copy;
//        if (!self.isCheck && [self.disablestand1TF.text isEqualToString:@""]) self.disablestand1TF.text = arrayM.firstObject;
//    }
    
    NSArray *DISABLE_STANDArray = self.downSelectDict[@"DISABLE_STAND"];
    if (DISABLE_STANDArray && DISABLE_STANDArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        [arrayM addObject:@"请选择"];
        for (NSDictionary *dict in DISABLE_STANDArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.disablestandTFArray = arrayM.copy;
        if (!self.isCheck && [self.disablestandTF.text isEqualToString:@""]) self.disablestandTF.text = arrayM.firstObject;
    }
    
    NSArray *PHYSICALArray = self.downSelectDict[@"PHYSICAL"];
    if (PHYSICALArray && PHYSICALArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in PHYSICALArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.bodyConditionTFArray = arrayM.copy;
        if (!self.isCheck && [self.bodyConditionTF.text isEqualToString:@""]) self.bodyConditionTF.text = arrayM.firstObject;
    }
    
    NSArray *if_01Array = self.downSelectDict[@"if_01"];
    if (if_01Array && if_01Array.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in if_01Array) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.basicLivingTFArray = arrayM.copy;
        if (!self.isCheck && [self.basicLivingTF.text isEqualToString:@""]) self.basicLivingTF.text = arrayM.firstObject;
    }
    
    NSArray *medicalTyArray = self.downSelectDict[@"medicalTy"];
    if (medicalTyArray && medicalTyArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in medicalTyArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.medicalTypeTFArray = arrayM.copy;
        if (!self.isCheck && [self.medicalTypeTF.text isEqualToString:@""]) self.medicalTypeTF.text = arrayM.firstObject;
    }
    
    NSArray *nationArray = self.downSelectDict[@"nation"];
    if (nationArray && nationArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in nationArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.nationTFArray = arrayM.copy;
        if (!self.isCheck && [self.nationTF.text isEqualToString:@""]) self.nationTF.text = arrayM.firstObject;
    }
    
    NSArray *relationArray = self.downSelectDict[@"relation"];
    if (relationArray && relationArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in relationArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.relationTFArray = arrayM.copy;
    }
    
    NSArray *serNeedsArray = self.downSelectDict[@"serNeeds"];
    if (serNeedsArray && serNeedsArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        [arrayM addObject:@"请选择"];
        for (NSDictionary *dict in serNeedsArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.serviceNeedsTFArray = arrayM.copy;
        if (!self.isCheck && [self.serviceNeedsTF.text isEqualToString:@""]) self.serviceNeedsTF.text = arrayM.firstObject;
    }
    
    NSArray *sexArray = self.downSelectDict[@"sex"];
    if (sexArray && sexArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in sexArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.sexTFArray = arrayM.copy;
//        if (!self.isCheck && [self.sexTF.text isEqualToString:@""]) self.sexTF.text = arrayM.firstObject;
    }
    
    NSArray *sf_ynArray = self.downSelectDict[@"sf_yn"];
    if (sf_ynArray && sf_ynArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in sf_ynArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.emergencyContactTFArray = arrayM.copy;
    }
    
    NSArray *survivalstateArray = self.downSelectDict[@"survivalstate"];
    if (survivalstateArray && survivalstateArray.count > 0) {
        NSMutableArray *arrayM = [[NSMutableArray alloc] initWithArray:@[]];
        for (NSDictionary *dict in survivalstateArray) {
            [arrayM addObject:[ValidateUtils validateNull:dict[@"value"]]];
        }
        self.survivalstateTFArray = arrayM.copy;
        if (!self.isCheck && [self.survivalstateTF.text isEqualToString:@""]) self.survivalstateTF.text = arrayM.firstObject;
    }
}

- (void)editButtonClickWithJump:(BOOL)JUMP {
    self.isCheck = false;
    self.navigationItem.rightBarButtonItem = nil;
    if (JUMP) {
        self.title = @"老龄人员基础信息编辑";
    } else {
        self.title = @"老龄人员基础信息采集";
    }
    [self arrangeDownSelectArrays];
    self.tableView.tableFooterView = self.tableViewFooterView;
    
    [self.sexTF removeFromSuperview];
    self.sexTF = nil;
    [self.birthdayTF removeFromSuperview];
    self.birthdayTF = nil;
    [self.nationTF removeFromSuperview];
    self.nationTF = nil;
    [self.regAdTF removeFromSuperview];
    self.regAdTF = nil;
    [self.nowAdTF removeFromSuperview];
    self.nowAdTF = nil;
    [self.medicalTypeTF removeFromSuperview];
    self.medicalTypeTF = nil;
    [self.bodyConditionTF removeFromSuperview];
    self.bodyConditionTF = nil;
    [self.disablestandTF removeFromSuperview];
    self.disablestandTF = nil;
    [self.disablestand1TF removeFromSuperview];
    self.disablestand1TF = nil;
    [self.serviceNeedsTF removeFromSuperview];
    self.serviceNeedsTF = nil;
    [self.survivalstateTF removeFromSuperview];
    self.survivalstateTF = nil;
    [self.basicLivingTF removeFromSuperview];
    self.basicLivingTF = nil;
    
    [self.tableView reloadData];
    [self arrangeData];
}

- (void)loadData {
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:LSAgeingDetail param:@{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"id":self.displayDataDict[@"id"]} completionHandler:^(id responseObject, NSError *connectionError) {
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                NSArray *dataArray = [responseObject objectForKey:@"data"];
                if (dataArray && dataArray.count > 0) {
                    self.displayDataDict = dataArray.firstObject;
                    if (self.displayDataDict && self.displayDataDict.count > 0) {
                        [self arrangeData];
                        NSArray *familyinfoEntitiesArray = self.displayDataDict[@"familyinfos"];
                        if (![familyinfoEntitiesArray isKindOfClass:[NSNull class]] && familyinfoEntitiesArray && familyinfoEntitiesArray.count > 0) {
                            NSDictionary *dict = familyinfoEntitiesArray.firstObject;
                            if (![[ValidateUtils validateNull:dict[@"fname"]] isEqualToString:@""]) {
                                self.OldPeopleFamilyDataCount = (int)familyinfoEntitiesArray.count;
                                [self.OldPeopleFamilyDataTFsArrayM removeAllObjects];
                                for (int i = 0; i < self.OldPeopleFamilyDataCount; i++) {
                                    [self addOneSectionOfTextFields];
                                }
                            } else {
                                self.OldPeopleFamilyDataCount = 0;
                            }
                        } else {
                            self.OldPeopleFamilyDataCount = 0;
                        }
                        [self.tableView reloadData];
                        if (self.isCheck && self.OldPeopleFamilyDataCount > 0) [self arrangeOldPeopleFamilyData];
                    }
                    if (self.jumpToEdit) [self editButtonClickWithJump:true];
                }
            } else {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

- (void)arrangeData {
    NSArray *DISABLE_LEVALArray = self.downSelectDict[@"DISABLE_LEVAL"];
    NSArray *DISABLE_STANDArray = self.downSelectDict[@"DISABLE_STAND"];
    NSArray *PHYSICALArray = self.downSelectDict[@"PHYSICAL"];
    NSArray *if_01Array = self.downSelectDict[@"if_01"];
    NSArray *medicalTyArray = self.downSelectDict[@"medicalTy"];
    NSArray *nationArray = self.downSelectDict[@"nation"];
    NSArray *serNeedsArray = self.downSelectDict[@"serNeeds"];
    NSArray *sexArray = self.downSelectDict[@"sex"];
    NSArray *survivalstateArray = self.downSelectDict[@"survivalstate"];
    
    self.nameTF.text = [ValidateUtils validateNull:self.displayDataDict[@"name"]];//姓名(Y)
    self.cardNoTF.text = [ValidateUtils validateNull:self.displayDataDict[@"cardNo"]];//身份证号(Y)
    NSString *sexString = @"";
    for (NSDictionary *dict in sexArray) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"sex"]]]) {
            sexString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.sexTF.text = sexString;//self.sexTFArray[[ValidateUtils validateNull:self.displayDataDict[@"sex"]].integerValue];//性别(Y)
    self.birthdayTF.text = [self timeStampToDate:self.displayDataDict[@"bridthday"]];//生日(Y)
    NSString *nationString = @"";
    for (NSDictionary *dict in nationArray) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"nation"]]]) {
            nationString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.nationTF.text = nationString;//self.nationTFArray[[ValidateUtils validateNull:self.displayDataDict[@"nation"]].integerValue];//民族(Y)
    self.regAdTF.text = [ValidateUtils validateNull:self.displayDataDict[@"regAdCountyName"]];//原户籍地(Y)
    self.regAdTF.placeholder = [ValidateUtils validateNull:self.displayDataDict[@"regAdCounty"]];
    self.domicileAdrTV.text = [ValidateUtils validateNull:self.displayDataDict[@"domicileAdr"]];//原户籍地地址(Y)
    self.nowAdTF.text = [ValidateUtils validateNull:self.displayDataDict[@"nowAdCountyName"]];//现住地(Y)
    self.nowAdTF.placeholder = [ValidateUtils validateNull:self.displayDataDict[@"nowAdCounty"]];
    self.locationAdrTV.text = [ValidateUtils validateNull:self.displayDataDict[@"locationAdr"]];//现所在地区名称(Y)
    self.phoneTF.text = [ValidateUtils validateNull:self.displayDataDict[@"phone"]];//联系电话(Y)
    self.incomeConditonTF.text = [ValidateUtils validateNull:self.displayDataDict[@"incomeConditon"]];//收入情况(Y)
    self.bankCardnoTF.text = [ValidateUtils validateNull:self.displayDataDict[@"bankCardno"]];//银行卡号
    NSString *medicalTyString = @"";
    for (NSDictionary *dict in medicalTyArray) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"medicalType"]]]) {
            medicalTyString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.medicalTypeTF.text = medicalTyString;//self.medicalTypeTFArray[[ValidateUtils validateNull:self.displayDataDict[@"medicalType"]].integerValue];//医保类型(Y)
    self.medicalCardnoTF.text = [ValidateUtils validateNull:self.displayDataDict[@"medicalCardno"]];//医疗卡号
    self.socialCardnoTF.text = [ValidateUtils validateNull:self.displayDataDict[@"socialCardno"]];//社保账号
    NSString *bodyConditionString = @"";
    for (NSDictionary *dict in PHYSICALArray) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"bodyCondition"]]]) {
            bodyConditionString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.bodyConditionTF.text = bodyConditionString;//self.bodyConditionTFArray[[self validateSelect:self.displayDataDict[@"bodyCondition"]]==0?0:[self validateSelect:self.displayDataDict[@"bodyCondition"]]-1];//身体状况(Y)
    if ([ValidateUtils validateNull:self.displayDataDict[@"bodyCondition"]].integerValue == 3) {
        self.bodyCondition_isShiNeng = true;
    } else {
        self.bodyCondition_isShiNeng = false;
    }
    if ([ValidateUtils validateNull:self.displayDataDict[@"bodyCondition"]].integerValue == 3) {
        NSMutableString *disablestandIdStringM = [[NSMutableString alloc] initWithString:@""];
        NSArray *disablestandIdStringArray = [[ValidateUtils validateNull:self.displayDataDict[@"disablestand"]] componentsSeparatedByString:@","];
        for (NSString *disablestandId in disablestandIdStringArray) {
            [disablestandIdStringM appendFormat:@"%@ ",[self getValueById:disablestandId fromArray:DISABLE_STANDArray]];
        }
        self.disablestandTF.text = [disablestandIdStringM substringToIndex:disablestandIdStringM.length-1];
        
        NSString *disableLevalString = @"";
        for (NSDictionary *dict in DISABLE_LEVALArray) {
            if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"disableLeval"]]]) {
                disableLevalString = [ValidateUtils validateNull:dict[@"value"]];
            }
        }
        self.disablestand1TF.text = disableLevalString;//self.disablestand1TFArray[[self validateSelect:self.displayDataDict[@"disableLeval"]]==0?0:[self validateSelect:self.displayDataDict[@"disableLeval"]]];//失能等级
    }
    
    
    NSMutableString *serviceNeedsStringM = [[NSMutableString alloc] initWithString:@""];
    NSArray *serviceNeedsStringArray = [[ValidateUtils validateNull:self.displayDataDict[@"serviceNeeds"]] componentsSeparatedByString:@","];
    for (NSString *serviceNeedsId in serviceNeedsStringArray) {
        [serviceNeedsStringM appendFormat:@"%@ ",[self getValueById:serviceNeedsId fromArray:serNeedsArray]];
    }
    self.serviceNeedsTF.text = [serviceNeedsStringM substringToIndex:serviceNeedsStringM.length-1];
    
    NSString *survivalstateString = @"";
    for (NSDictionary *dict in survivalstateArray) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"survivalstate"]]]) {
            survivalstateString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.survivalstateTF.text = survivalstateString;//@"未知";
    NSString *if_01ArrayString = @"";
    for (NSDictionary *dict in if_01Array) {
        if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:self.displayDataDict[@"basicLiving"]]]) {
            if_01ArrayString = [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    self.basicLivingTF.text = if_01ArrayString;//self.basicLivingTFArray[[ValidateUtils validateNull:self.displayDataDict[@"basicLiving"]].integerValue];//是否低保(Y)
    self.remarkTV.text = [ValidateUtils validateNull:self.displayDataDict[@"remark"]];//备注
 
    [self.tableView reloadData];
}

- (void)arrangeOldPeopleFamilyData {
    NSArray *familyinfoEntitiesArray = self.displayDataDict[@"familyinfos"];
    NSArray *sexArray = self.downSelectDict[@"sex"];
    NSArray *relationArray = self.downSelectDict[@"relation"];
    NSArray *sf_ynArray = self.downSelectDict[@"sf_yn"];
    for (int i = 0; i < self.OldPeopleFamilyDataTFsArrayM.count; i++) {
        NSArray *textFieldArray = self.OldPeopleFamilyDataTFsArrayM[i];
        NSDictionary *dataDict = familyinfoEntitiesArray[i];
        UITextField *nameTF = textFieldArray.firstObject;
        UITextField *cardNoTF = textFieldArray[1];
        UITextField *sexTF = textFieldArray[2];
        UITextField *phoneTF = textFieldArray[3];
        UITextField *relationTF = textFieldArray[4];
        NZKTextView *workUnitTV = textFieldArray[5];
        UITextField *ifUrgencyLinkmanTF = textFieldArray.lastObject;
        nameTF.text = [ValidateUtils validateNull:dataDict[@"fname"]];
        NSString *sexString = @"";
        for (NSDictionary *dict in sexArray) {
            if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:dataDict[@"fsex"]]]) {
                sexString = [ValidateUtils validateNull:dict[@"value"]];
            }
        }
        sexTF.text = sexString;//[ValidateUtils validateNull:dataDict[@"fsex"]];
        phoneTF.text = [ValidateUtils validateNull:dataDict[@"fphone"]];
        cardNoTF.text = [ValidateUtils validateNull:dataDict[@"fcardNo"]];
        NSString *relationString = @"";
        for (NSDictionary *dict in relationArray) {
            if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:dataDict[@"relation"]]]) {
                relationString = [ValidateUtils validateNull:dict[@"value"]];
            }
        }
        relationTF.text = relationString;//[ValidateUtils validateNull:dataDict[@"relation"]];
        workUnitTV.text = [ValidateUtils validateNull:dataDict[@"wordUnit"]];
        NSString *sf_ynString = @"";
        for (NSDictionary *dict in sf_ynArray) {
            if ([dict[@"id"] isEqualToString:[ValidateUtils validateNull:dataDict[@"ifUrgencyLinkman"]]]) {
                sf_ynString = [ValidateUtils validateNull:dict[@"value"]];
            }
        }
        ifUrgencyLinkmanTF.text = sf_ynString;//[ValidateUtils validateNull:dataDict[@"ifUrgencyLinkman"]];
    }
}

- (NSInteger)validateSelect:(NSString *)string {
    if (!string || [string isKindOfClass:[NSNull class]]) {
        return 0;
    } else {
        return string.integerValue;
    }
}

- (NSString *)timeStampToDate:(NSString *)timeStampString {
    // iOS 生成的时间戳是10位
    if (![[ValidateUtils validateNull:timeStampString] isEqualToString:@""] && !([ValidateUtils validateNull:timeStampString].integerValue == 0)) {
        NSTimeInterval interval = [timeStampString doubleValue] / 1000.0;
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        return [formatter stringFromDate:date];
    } else {
        return @"";
    }
}

- (void)setDisplayDataDict:(NSDictionary *)displayDataDict {
    _displayDataDict = displayDataDict;
}

#pragma mark - 信息提交
- (void)submitButtonClick {
    if ([self.nameTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请输入姓名"];
        return;
    } else if ([self.cardNoTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请填写身份证号"];
        return;
    } else if (![ValidateUtils validateIDCardNumber:self.cardNoTF.text]) {
        [MBProgressHUD showTipMessageInWindow:@"身份证号填写有误"];
        return;
    } else if ([ValidateUtils getPersonAgeFromIdCard:self.cardNoTF.text] < 50) {
        [MBProgressHUD showTipMessageInWindow:@"老人年龄必须大于50周岁"];
        return;
    } else if ([self.nationTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择民族"];
        return;
    } else if ([self.regAdTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择原户籍地"];
        return;
    } else if ([self.domicileAdrTV.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请填写户籍地详细地址"];
        return;
    } else if ([self.nowAdTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择现住地"];
        return;
    } else if ([self.locationAdrTV.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请填写现住地详细地址"];
        return;
    } else if ([self.phoneTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请填写联系电话"];
        return;
    } else if (![ValidateUtils validateMobile:self.phoneTF.text]) {
        [MBProgressHUD showTipMessageInWindow:@"联系电话填写有误"];
        return;
    } else if ([self.incomeConditonTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请填写收入状况"];
        return;
    } else if (![self.bankCardnoTF.text isEqualToString:@""] && ![ValidateUtils validatebankCardNumber:self.bankCardnoTF.text]) {
        [MBProgressHUD showTipMessageInWindow:@"银行卡号填写有误"];
        return;
    } else if ([self.medicalTypeTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择医保类型"];
        return;
    } else if ([self.bodyConditionTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择身体状况"];
        return;
    } else if ([self.bodyConditionTF.text isEqualToString:@"失能"] && ([self.disablestandTF.text isEqualToString:@""] || [self.disablestandTF.text isEqualToString:@"请选择"])) {
        [MBProgressHUD showTipMessageInWindow:@"请选择失能标准"];
        return;
    } else if ([self.bodyConditionTF.text isEqualToString:@"失能"] && ([self.disablestand1TF.text isEqualToString:@""] || [self.disablestand1TF.text isEqualToString:@"请选择"])) {
        [MBProgressHUD showTipMessageInWindow:@"请选择失能等级"];
        return;
    } else if ([self.serviceNeedsTF.text isEqualToString:@""] || [self.serviceNeedsTF.text isEqualToString:@"请选择"]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择服务需求"];
        return;
    } else if ([self.survivalstateTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择存活状态"];
        return;
    } else if ([self.basicLivingTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择是否低保"];
        return;
    }
    if (self.OldPeopleFamilyDataCount > 0) {
        for (int i = 0; i < self.OldPeopleFamilyDataTFsArrayM.count; i++) {
            NSArray *textFieldArray = self.OldPeopleFamilyDataTFsArrayM[i];
            UITextField *nameTF = textFieldArray.firstObject;
            UITextField *cardNoTF = textFieldArray[1];
            UITextField *sexTF = textFieldArray[2];
            UITextField *phoneTF = textFieldArray[3];
            UITextField *relationTF = textFieldArray[4];
            NZKTextView *workUnitTV = textFieldArray[5];
            if ([nameTF.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请填写第%d个老人家庭信息姓名",i+1]];
                return;
            } else if ([sexTF.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请选择第%d个老人家庭信息性别",i+1]];
                return;
            } else if ([phoneTF.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请填写第%d个老人家庭信息联系电话",i+1]];
                return;
            } else if (![phoneTF.text isEqualToString:@""] && ![ValidateUtils validateMobile:phoneTF.text]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"第%d个老人家庭联系电话格式错误",i+1]];
                return;
            } else if ([cardNoTF.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请填写第%d个老人家庭信息身份证号",i+1]];
                return;
            } else if (![cardNoTF.text isEqualToString:@""] && ![ValidateUtils validateIDCardNumber:cardNoTF.text]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"第%d个老人家庭身份证号格式错误",i+1]];
                return;
            } else if ([relationTF.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请选择第%d个老人家庭信息关系",i+1]];
                return;
            } else if ([workUnitTV.text isEqualToString:@""]) {
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"请填写第%d个老人家庭信息工作单位",i+1]];
                return;
            }
        }
    }
    
    NSArray *DISABLE_LEVALArray = self.downSelectDict[@"DISABLE_LEVAL"];
    NSArray *DISABLE_STANDArray = self.downSelectDict[@"DISABLE_STAND"];
    NSArray *PHYSICALArray = self.downSelectDict[@"PHYSICAL"];
    NSArray *if_01Array = self.downSelectDict[@"if_01"];
    NSArray *medicalTyArray = self.downSelectDict[@"medicalTy"];
    NSArray *nationArray = self.downSelectDict[@"nation"];
    NSArray *relationArray = self.downSelectDict[@"relation"];
    NSArray *serNeedsArray = self.downSelectDict[@"serNeeds"];
    NSArray *sexArray = self.downSelectDict[@"sex"];
    NSArray *sf_ynArray = self.downSelectDict[@"sf_yn"];
    NSArray *survivalstateArray = self.downSelectDict[@"survivalstate"];
    
    NSMutableDictionary *paramM = [[NSMutableDictionary alloc] initWithDictionary:@{
                                                                                        @"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],
                                                                                         @"name":self.nameTF.text,
                                                                                         @"cardNo":self.cardNoTF.text,
                                                                                         @"sex":[self getIdByValue:self.sexTF.text fromArray:sexArray],
                                                                                         @"bridthday":self.birthdayTF.text,
                                                                                         @"nation":[self getIdByValue:self.nationTF.text fromArray:nationArray],
                                                                                        @"regAdPro":[self.regAdTF.placeholder.mutableCopy substringToIndex:2],
                                                                                        @"regAdCity":[self.regAdTF.placeholder.mutableCopy substringToIndex:4],
                                                                                        @"regAdCounty":self.regAdTF.placeholder,
                                                                                        @"regAdStreets":@"",
                                                                                         @"domicileAdr":[ValidateUtils validateNull:self.domicileAdrTV.text],
                                                                                        @"nowAdPro":[self.nowAdTF.placeholder.mutableCopy substringToIndex:2],
                                                                                        @"nowAdCity":[self.nowAdTF.placeholder.mutableCopy substringToIndex:4],
                                                                                        @"nowAdCounty":self.nowAdTF.placeholder,
                                                                                        @"nowAdStreets":@"",
                                                                                         @"locationAdr":[ValidateUtils validateNull:self.locationAdrTV.text],
                                                                                         @"phone":self.phoneTF.text,
                                                                                         @"incomeConditon":[NSString stringWithFormat:@"%.2f",self.incomeConditonTF.text.floatValue],
                                                                                         @"medicalType":[self getIdByValue:self.medicalTypeTF.text fromArray:medicalTyArray],
                                                                                         @"bodyCondition":[self getIdByValue:self.bodyConditionTF.text fromArray:PHYSICALArray],
                                                                                         @"basicLiving":[self getIdByValue:self.basicLivingTF.text fromArray:if_01Array],
                                                                                        @"survivalstate":[self getIdByValue:self.survivalstateTF.text fromArray:survivalstateArray]
                                                                                        }];
    NSMutableString *serviceNeedsTFStringM = [[NSMutableString alloc] initWithString:@""];
    NSArray *serviceNeedsTFStringArray = [self.serviceNeedsTF.text componentsSeparatedByString:@" "];
    for (NSString *serviceNeed in serviceNeedsTFStringArray) {
        [serviceNeedsTFStringM appendFormat:@"%@,",[self getIdByValue:serviceNeed fromArray:serNeedsArray]];
    }
    [paramM setValue:[serviceNeedsTFStringM substringToIndex:serviceNeedsTFStringM.length-1] forKey:@"serviceNeeds"];
    
    if (![self.bankCardnoTF.text isEqualToString:@""]) {
        [paramM setValue:self.bankCardnoTF.text forKey:@"bankCardno"];
    } else {
        [paramM setValue:@"" forKey:@"bankCardno"];
    }
    if (![self.medicalCardnoTF.text isEqualToString:@""]) {
        [paramM setValue:self.medicalCardnoTF.text forKey:@"medicalCardno"];
    } else {
        [paramM setValue:@"" forKey:@"medicalCardno"];
    }
    if (![self.socialCardnoTF.text isEqualToString:@""]) {
        [paramM setValue:self.socialCardnoTF.text forKey:@"socialCardno"];
    } else {
        [paramM setValue:@"" forKey:@"socialCardno"];
    }
    if (![self.disablestandTF.text isEqualToString:@""] && [self.bodyConditionTF.text isEqualToString:@"失能"]) {
        if ([self.disablestandTF.text isEqualToString:@"请选择"]) {
            [paramM setValue:@"" forKey:@"disablestand"];
        } else {
            NSMutableString *disablestandTFStringM = [[NSMutableString alloc] initWithString:@""];
            NSArray *disablestandTFStringArray = [self.disablestandTF.text componentsSeparatedByString:@" "];
            for (NSString *disablestand in disablestandTFStringArray) {
                [disablestandTFStringM appendFormat:@"%@,",[self getIdByValue:disablestand fromArray:DISABLE_STANDArray]];
            }
            [paramM setValue:[disablestandTFStringM substringToIndex:disablestandTFStringM.length-1] forKey:@"disablestand"];
        }
    } else {
        [paramM setValue:@"" forKey:@"disablestand"];
    }
    if (![self.disablestand1TF.text isEqualToString:@""] && [self.bodyConditionTF.text isEqualToString:@"失能"]) {
        if ([self.disablestand1TF.text isEqualToString:@"请选择"]) {
            [paramM setValue:@"" forKey:@"disableLeval"];
        } else {
            [paramM setValue:[self getIdByValue:self.disablestand1TF.text fromArray:DISABLE_LEVALArray] forKey:@"disableLeval"];
        }
    } else {
        [paramM setValue:@"" forKey:@"disableLeval"];
    }
    if (![self.remarkTV.text isEqualToString:@""]) {
        [paramM setValue:self.remarkTV.text forKey:@"remark"];
    } else {
        [paramM setValue:@"" forKey:@"remark"];
    }
    
    if (self.OldPeopleFamilyDataCount > 0) {
        NSMutableArray *oldPeopleFamilyDataM = [[NSMutableArray alloc] init];
        for (NSArray *textFieldArray in self.OldPeopleFamilyDataTFsArrayM) {
            UITextField *nameTF = textFieldArray.firstObject;
            UITextField *cardNoTF = textFieldArray[1];
            UITextField *sexTF = textFieldArray[2];
            UITextField *phoneTF = textFieldArray[3];
            UITextField *relationTF = textFieldArray[4];
            NZKTextView *workUnitTV = textFieldArray[5];
            UITextField *ifUrgencyLinkmanTF = textFieldArray.lastObject;
            NSString *sexString = [self getIdByValue:sexTF.text fromArray:sexArray];
            NSString *relationString = [self getIdByValue:relationTF.text fromArray:relationArray];
            NSString *ifUrgencyLinkmanString = [self getIdByValue:ifUrgencyLinkmanTF.text fromArray:sf_ynArray];
            [oldPeopleFamilyDataM addObject:@{@"fname":nameTF.text,
                                              @"fsex":sexString,
                                              @"fphone":phoneTF.text,
                                              @"fcardNo":cardNoTF.text,
                                              @"relation":relationString,
                                              @"wordUnit":workUnitTV.text,
                                              @"ifUrgencyLinkman":ifUrgencyLinkmanString
                                              }];
        }
        NSData *data = [NSJSONSerialization dataWithJSONObject:oldPeopleFamilyDataM.copy options:NSJSONWritingPrettyPrinted error:nil];
        NSString *oldPeopleFamilyString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        [paramM setObject:oldPeopleFamilyString forKey:@"familyinfoEntities"];
    } else {
        NSArray *dataArray = @[@{@"fname":@"",
                                 @"fsex":@"",
                                 @"fphone":@"",
                                 @"fcardNo":@"",
                                 @"relation":@"",
                                 @"wordUnit":@"",
                                 @"ifUrgencyLinkman":@""
                                 }];
//        [paramM setObject:@[@{@"fname":@"",
//                              @"fsex":@"",
//                              @"fphone":@"",
//                              @"fcardNo":@"",
//                              @"relation":@"",
//                              @"wordUnit":@"",
//                              @"ifUrgencyLinkman":@""
//                              }] forKey:@"familyinfoEntities"];
        NSData *data = [NSJSONSerialization dataWithJSONObject:dataArray options:NSJSONWritingPrettyPrinted error:nil];
        NSString *oldPeopleFamilyString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        [paramM setObject:oldPeopleFamilyString forKey:@"familyinfoEntities"];
    }
    
    WS
    NSString *url = LsAgeingAdd;
    if (self.isCheckedBefore) {
        url = LSAgeingUpdate;
        [paramM setValue:self.displayDataDict[@"id"] forKey:@"id"];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:url param:paramM completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                if (self.isCheckedBefore) {
                    if (![[ValidateUtils validateNull:responseObject[@"message"]] isEqualToString:@""]) {
                        [MBProgressHUD showTipMessageInWindow:responseObject[@"message"]];
                    }
                } else {
                    if (![[ValidateUtils validateNull:responseObject[@"message"]] isEqualToString:@""]) {
                        [MBProgressHUD showTipMessageInWindow:responseObject[@"message"]];
                    }
                }
                if (self.refreshBlock) {
                    self.refreshBlock();
                }
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [weakSelf.navigationController popViewControllerAnimated:true];
                });
            } else {
                if (![[ValidateUtils validateNull:responseObject[@"message"]] isEqualToString:@""]) {
                    [MBProgressHUD showTipMessageInWindow:responseObject[@"message"]];
                }
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
    /*
    NSURL *url = [NSURL URLWithString:LsAgeingAdd];
    if (self.isCheck) {
        url = [NSURL URLWithString:LSAgeingUpdate];
    }
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"POST";
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Accept"];
    [request setTimeoutInterval:15];
    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];

    NSData *data = [NSJSONSerialization dataWithJSONObject:paramM options:NSJSONWritingPrettyPrinted error:nil];
    request.HTTPBody = data;
    // 4.发送请求
    NSURLSession *session = [NSURLSession sharedSession];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [hud hideAnimated:true];
        }];
        if (!error) {
            NSString *encodeString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSString *encodeStringChecked = [JSONUtils checkJsonString:encodeString];
            NSDictionary *object = [JSONUtils objectFromJSONString:encodeStringChecked];
            if (object) {
                NSNumber *status = [object objectForKey:@"status"];
                if ([status integerValue] == 200) {
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                            [weakSelf.navigationController popViewControllerAnimated:true];
                        });
                    }];
                } else {
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        [MBProgressHUD showTipMessageInWindow:[object objectForKey:@"msg"]];
                    }];
                }
            } else {
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    [MBProgressHUD showTipMessageInWindow:@"上传失败"];
                }];
            }
        } else {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"%@",error.localizedDescription]];
            }];
        }
    }];
    [task resume];
     */
}

- (NSString *)getIdByValue:(NSString *)value fromArray:(NSArray *)dateArray {
    for (NSDictionary *dict in dateArray) {
        if (![[ValidateUtils validateNull:dict[@"value"]] isEqualToString:@""] && [dict[@"value"] isEqualToString:value]) {
            return [ValidateUtils validateNull:dict[@"id"]];
        }
    }
    return @"";
}

- (NSString *)getValueById:(NSString *)Id fromArray:(NSArray *)dateArray {
    for (NSDictionary *dict in dateArray) {
        if (![[ValidateUtils validateNull:dict[@"id"]] isEqualToString:@""] && [dict[@"id"] isEqualToString:Id]) {
            return [ValidateUtils validateNull:dict[@"value"]];
        }
    }
    return @"";
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.OldPeopleFamilyDataCount == 0) {
        return 2;
    }
    return 1+self.OldPeopleFamilyDataCount;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        if (self.bodyCondition_isShiNeng) {
            return self.contentArray_isShiNeng.count;
        } else {
            return self.contentArray.count;
        }
    } else {
        if (self.OldPeopleFamilyDataCount < section) {
            return 0;
        } else {
            return self.familyinfoEntitiesContentArray.count;
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        LSInfoCollectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OldPeopleFoundationDataCollectCellID forIndexPath:indexPath];
        if (self.isCheck) {
            if (self.bodyCondition_isShiNeng) {
                cell.leftLabel.text = self.contentArray_isShiNeng[indexPath.row];
                [cell.leftLabel sizeToFit];
                cell.xingImageView.hidden = true;
            } else {
                cell.leftLabel.text = self.contentArray[indexPath.row];
                [cell.leftLabel sizeToFit];
                cell.xingImageView.hidden = true;
            }
        } else {
            if (self.bodyCondition_isShiNeng) {
                cell.leftLabel.text = self.contentArray_isShiNeng[indexPath.row];
                [cell.leftLabel sizeToFit];
                if (indexPath.row == 11 || indexPath.row == 13 || indexPath.row == 14 || indexPath.row == 21) {
                    cell.xingImageView.hidden = true;
                } else {
                    cell.xingImageView.hidden = false;
                }
            } else {
                cell.leftLabel.text = self.contentArray[indexPath.row];
                [cell.leftLabel sizeToFit];
                if (indexPath.row == 11 || indexPath.row == 13 || indexPath.row == 14 || indexPath.row == 19) {
                    cell.xingImageView.hidden = true;
                } else {
                    cell.xingImageView.hidden = false;
                }
            }
        }
        
        for (UIView *subView in cell.contentView.subviews) {
            if ([subView isKindOfClass:UITextField.class] || [subView isKindOfClass:[UITextView class]] || [subView isKindOfClass:[NZKTextView class]]) {
                [subView removeFromSuperview];
            }
        }
        
        LSInfoCollectTableViewCell *currentCell = cell;
        if (indexPath.row == 0) {
            [currentCell.contentView addSubview:self.nameTF];
            [self.nameTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 1) {
            [currentCell.contentView addSubview:self.cardNoTF];
            [self.cardNoTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 2) {
            [currentCell.contentView addSubview:self.birthdayTF];
            [self.birthdayTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 3) {
            [currentCell.contentView addSubview:self.sexTF];
            [self.sexTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 4) {
            [currentCell.contentView addSubview:self.nationTF];
            [self.nationTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 5) {
            [currentCell.contentView addSubview:self.regAdTF];
            [self.regAdTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 6) {
            [currentCell.contentView addSubview:self.domicileAdrTV];
            [self.domicileAdrTV mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 7) {
            [currentCell.contentView addSubview:self.nowAdTF];
            [self.nowAdTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 8) {
            [currentCell.contentView addSubview:self.locationAdrTV];
            [self.locationAdrTV mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 9) {
            [currentCell.contentView addSubview:self.phoneTF];
            [self.phoneTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 10) {
            [currentCell.contentView addSubview:self.incomeConditonTF];
            [self.incomeConditonTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 11) {
            [currentCell.contentView addSubview:self.bankCardnoTF];
            [self.bankCardnoTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 12) {
            [currentCell.contentView addSubview:self.medicalTypeTF];
            [self.medicalTypeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 13) {
            [currentCell.contentView addSubview:self.medicalCardnoTF];
            [self.medicalCardnoTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 14) {
            [currentCell.contentView addSubview:self.socialCardnoTF];
            [self.socialCardnoTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 15) {
            [currentCell.contentView addSubview:self.bodyConditionTF];
            [self.bodyConditionTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 16 && self.bodyCondition_isShiNeng) {
            [currentCell.contentView addSubview:self.disablestandTF];
            [self.disablestandTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if (indexPath.row == 17 && self.bodyCondition_isShiNeng) {
            [currentCell.contentView addSubview:self.disablestand1TF];
            [self.disablestand1TF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if ((indexPath.row == 18 && self.bodyCondition_isShiNeng) || (indexPath.row == 16 && !self.bodyCondition_isShiNeng)) {
            [currentCell.contentView addSubview:self.serviceNeedsTF];
            [self.serviceNeedsTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if ((indexPath.row == 19 && self.bodyCondition_isShiNeng) || (indexPath.row == 17 && !self.bodyCondition_isShiNeng)) {
            [currentCell.contentView addSubview:self.survivalstateTF];
            [self.survivalstateTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if ((indexPath.row == 20 && self.bodyCondition_isShiNeng) || (indexPath.row == 18 && !self.bodyCondition_isShiNeng)) {
            [currentCell.contentView addSubview:self.basicLivingTF];
            [self.basicLivingTF mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        } else if ((indexPath.row == 21 && self.bodyCondition_isShiNeng) || (indexPath.row == 19 && !self.bodyCondition_isShiNeng)) {
            [currentCell.contentView addSubview:self.remarkTV];
            [self.remarkTV mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(currentCell.contentView.mas_bottom);
            }];
        }
        return cell;
    } else {
        LSInfoCollectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OldPeopleFoundationDataCollectCellID forIndexPath:indexPath];
        cell.leftLabel.text = self.familyinfoEntitiesContentArray[indexPath.row];
        [cell.leftLabel sizeToFit];
        if (self.isCheck) {
            cell.xingImageView.hidden = true;
        } else {
            if (indexPath.row == 6) {
                cell.xingImageView.hidden = true;
            } else {
                cell.xingImageView.hidden = false;
            }
        }
        for (UIView *subView in cell.contentView.subviews) {
            if ([subView isKindOfClass:UITextField.class] || [subView isKindOfClass:[UITextView class]] || [subView isKindOfClass:[NZKTextView class]]) {
                [subView removeFromSuperview];
            }
        }
        
        NSArray *textFieldArray = self.OldPeopleFamilyDataTFsArrayM[indexPath.section-1];
        if (indexPath.row == 5) {
            NZKTextView *workUnitTV = textFieldArray[5];
            [cell.contentView addSubview:workUnitTV];
            [workUnitTV mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(cell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(cell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(cell.contentView.mas_bottom);
            }];
        } else {
            UITextField *textField = textFieldArray[indexPath.row];
            [cell.contentView addSubview:textField];
            if (indexPath.row == 4) {
                if (!self.isCheck && [textField.text isEqualToString:@""]) textField.text = self.relationTFArray.firstObject;
            } else if (indexPath.row == 6) {
                if (!self.isCheck && [textField.text isEqualToString:@""]) textField.text = self.emergencyContactTFArray.firstObject;
            }
            [textField mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.leftLabel.mas_right).with.offset(12);
                make.right.equalTo(cell.contentView.mas_right).with.offset(-15);
                make.top.equalTo(cell.contentView.mas_top).with.offset(8);
                make.bottom.equalTo(cell.contentView.mas_bottom);
            }];
        }
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section!=0 && indexPath.row == 6) {
        return 44;
    } if (indexPath.section!=0 && indexPath.row == 5) {
        return 100;
    }
    if (indexPath.row == 6 || indexPath.row == 8) {
        return 100;
    }
    if ((indexPath.row == 21 && self.bodyCondition_isShiNeng) || (indexPath.row == 19 && !self.bodyCondition_isShiNeng)) {
        return 100;
    }
    
    return 44;
}

#pragma mark - 弹窗
- (void)showSelectControllerForTextField:(UITextField *)textField WithContentArray:(NSArray *)contentArray {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i = 0; i < contentArray.count; i++) {
        [alertC addActionTarget:alertC title:contentArray[i] color:NAV_COLOR action:^(UIAlertAction *action) {
            textField.text = contentArray[i];
        }];
    }
    [alertC addCancelActionTarget:alertC color:NAV_COLOR title:@"取消"];
    [self presentViewController:alertC animated:true completion:nil];
}

- (void)showDateSelectControllerForTextField:(UITextField *)textField WithTitle:(NSString *)title {
    LSDatePickViewController *alertVC = [LSDatePickViewController alertControllerWithTitle:[NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n\n\n\n",title] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    alertVC.datePicker.datePickerMode = UIDatePickerModeDate;
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 获取当前datePicker上面选择的时间
        NSDate *date = alertVC.datePicker.date;
        // NSLog(@"-----%@", date);
        // 创建时间格式化工具
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        df.dateFormat = @"yyyy-MM-dd";
        NSString *str = [df stringFromDate:date];
        textField.text = [NSString stringWithFormat:@"%@",str];
        textField.backgroundColor = UIColor.whiteColor;
    }];
    [alertVC addAction:cancelAction];
    [alertVC addAction:okAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)showLocationSelectControllerForTextField:(UITextField *)textField WithTitle:(NSString *)title {
    LSInfoSelectController *locationSelectC = [LSInfoSelectController alertControllerWithTitle:[NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n\n\n",title] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        textField.text = [NSString stringWithFormat:@"%@  %@  %@",locationSelectC.pickerViewSelectedShengString,locationSelectC.pickerViewSelectedShiString,locationSelectC.pickerViewSelectedQuString];
        textField.placeholder = locationSelectC.pickerViewSelectedCode;
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [locationSelectC addAction:confirmAction];
    [locationSelectC addAction:cancelAction];
    [self presentViewController:locationSelectC animated:true completion:nil];
}

- (void)showMultipleSelectViewWithArray:(NSArray *)selectArray forTextfield:(UITextField *)selectTF {
    NSMutableArray *selectArrayM = [[NSMutableArray alloc] initWithArray:selectArray];
    [selectArrayM removeObjectAtIndex:0];
    NSArray *selectedArray = @[];
    if (![selectTF.text isEqualToString:@"请选择"] && ![[ValidateUtils validateNull:selectTF.text] isEqualToString:@""]) {
        selectedArray = [selectTF.text componentsSeparatedByString:@" "];
    }
    LSMultipleSelectView *selectedView = [[LSMultipleSelectView alloc] initWithSelectObjects:selectArrayM.copy andSelectedObjects:selectedArray didSelectObjects:^(NSArray * _Nonnull selectObjects) {
        if (selectObjects.count > 0) {
            NSMutableString *stringM = [[NSMutableString alloc] initWithString:@""];
            for (NSString *string in selectObjects) {
                [stringM appendFormat:@"%@ ",string];
            }
            selectTF.text = [stringM substringToIndex:stringM.length-1];
            // 如果是选择的失能标准，则对失能登记赋值
            if (selectTF == self.disablestandTF) {
                if (selectObjects.count <= 2) {
                    self.disablestand1TF.text = self.disablestand1TFArray.firstObject;
                } else if (selectObjects.count > 2 && selectObjects.count <= 4) {
                    self.disablestand1TF.text = self.disablestand1TFArray[1];
                } else {
                    self.disablestand1TF.text = self.disablestand1TFArray.lastObject;
                }
            }
        } else {
            selectTF.text = @"请选择";
            if (selectTF == self.disablestandTF) {
                self.disablestand1TF.text = @"";
            }
        }
    }];
    [selectedView show];
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == self.sexTF) {
//        if (!self.isCheck) [self showSelectControllerForTextField:self.sexTF WithContentArray:self.sexTFArray];
        return false;
    } else if (textField == self.birthdayTF) {
//        if (!self.isCheck) [self showDateSelectControllerForTextField:self.birthdayTF WithTitle:@"请选择出生日期"];
        return false;
    } else if (textField == self.nationTF) {
        if (!self.isCheck) [self showSelectControllerForTextField:self.nationTF WithContentArray:self.nationTFArray];
        return false;
    } else if (textField == self.regAdTF) {
        if (!self.isCheck) [self showLocationSelectControllerForTextField:self.regAdTF WithTitle:@"请选择原户籍地"];
        return false;
    } else if (textField == self.nowAdTF) {
        if (!self.isCheck) [self showLocationSelectControllerForTextField:self.nowAdTF WithTitle:@"请选择现住地"];
        return false;
    } else if (textField == self.medicalTypeTF) {
        if (!self.isCheck) [self showSelectControllerForTextField:self.medicalTypeTF WithContentArray:self.medicalTypeTFArray];
        return false;
    } else if (textField == self.bodyConditionTF) {
        if (!self.isCheck) {
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
            WS
            for (int i = 0; i < self.bodyConditionTFArray.count; i++) {
                [alertC addActionTarget:alertC title:self.bodyConditionTFArray[i] color:NAV_COLOR action:^(UIAlertAction *action) {
                    weakSelf.bodyConditionTF.text = weakSelf.bodyConditionTFArray[i];
                    if (i == self.bodyConditionTFArray.count-1) {
                        weakSelf.bodyCondition_isShiNeng = true;
                    } else {
                        weakSelf.bodyCondition_isShiNeng = false;
                    }
//                    [weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                    [weakSelf.tableView reloadData];
                }];
            }
            [alertC addCancelActionTarget:alertC color:NAV_COLOR title:@"取消"];
            [self presentViewController:alertC animated:true completion:nil];
        }
        return false;
    } else if (textField == self.disablestandTF) {
//        if (!self.isCheck) [self showSelectControllerForTextField:self.disablestandTF WithContentArray:self.disablestandTFArray];
        if (!self.isCheck) {
            [self showMultipleSelectViewWithArray:self.disablestandTFArray forTextfield:self.disablestandTF];
        }
        return false;
    } else if (textField == self.disablestand1TF) {
//        if (!self.isCheck) [self showSelectControllerForTextField:self.disablestand1TF WithContentArray:self.disablestand1TFArray];
        return false;
    } else if (textField == self.serviceNeedsTF) {
//        if (!self.isCheck) [self showSelectControllerForTextField:self.serviceNeedsTF WithContentArray:self.serviceNeedsTFArray];
        if (!self.isCheck) {
            [self showMultipleSelectViewWithArray:self.serviceNeedsTFArray forTextfield:self.serviceNeedsTF];
        }
        return false;
    } else if (textField == self.survivalstateTF) {
        if (!self.isCheck) [self showSelectControllerForTextField:self.survivalstateTF WithContentArray:self.survivalstateTFArray];
        return false;
    } else if (textField == self.basicLivingTF) {
        if (!self.isCheck) [self showSelectControllerForTextField:self.basicLivingTF WithContentArray:self.basicLivingTFArray];
        return false;
    }
    for (NSArray *textFieldArray in self.OldPeopleFamilyDataTFsArrayM) {
        if (textField == textFieldArray[2]) {
            if (!self.isCheck) [self showSelectControllerForTextField:textField WithContentArray:self.sexTFArray];
            return false;
        } else if (textField == textFieldArray[4]) {
            if (!self.isCheck) [self showSelectControllerForTextField:textField WithContentArray:self.relationTFArray];
            return false;
        } else if (textField == textFieldArray.lastObject) {
            if (!self.isCheck) [self showSelectControllerForTextField:textField WithContentArray:self.basicLivingTFArray];
            return false;
        }
    }
    if (self.isCheck) {
        return false;
    } else {
        return true;
    }
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (textField == self.cardNoTF) {
        if ([textField.text isEqualToString:@""]) {
            return true;
        } else if (![ValidateUtils validateIDCardNumber:textField.text]) {
            [MBProgressHUD showTipMessageInWindow:@"身份证输入有误"];
            textField.text = @"";
        } else if ([ValidateUtils getPersonAgeFromIdCard:textField.text] < 50) {
            [MBProgressHUD showTipMessageInWindow:@"老人年龄必须大于50周岁"];
            textField.text = @"";
        } else {
            //截取身份证中出行人出生日期中的年、月、日
            NSString *personYear = [textField.text substringWithRange:NSMakeRange(6, 4)];
            NSString *personMonth = [textField.text substringWithRange:NSMakeRange(10, 2)];
            NSString *personDay = [textField.text substringWithRange:NSMakeRange(12, 2)];
            NSMutableString *birthdayString = [[NSMutableString alloc] initWithString:personYear];
            [birthdayString appendFormat:@"-%@",personMonth];
            [birthdayString appendFormat:@"-%@",personDay];
            self.birthdayTF.text = birthdayString;
            //获取身份证号中的性别
            NSInteger gender = [ValidateUtils getGenderFromIdCard:textField.text];
            if (gender == 2) {//女
                self.sexTF.text = @"女";
            } else {
                self.sexTF.text = @"男";
            }
        }
    }
    
    if (textField == self.phoneTF) {
        if ([textField.text isEqualToString:@""]) {
            return true;
        } else if (![ValidateUtils validateMobile:self.phoneTF.text]) {
            [MBProgressHUD showTipMessageInWindow:@"联系电话填写有误"];
            textField.text = @"";
        }
    }
    
    if (textField == self.bankCardnoTF) {
        if ([textField.text isEqualToString:@""]) {
            return true;
        } else if (![ValidateUtils validatebankCardNumber:self.bankCardnoTF.text]) {
            [MBProgressHUD showTipMessageInWindow:@"银行卡号填写有误"];
            textField.text = @"";
        }
    }
    
    for (NSArray *textFieldArray in self.OldPeopleFamilyDataTFsArrayM) {
        UITextField *cardNoTF = textFieldArray[1];
        UITextField *sexTF = textFieldArray[2];
        UITextField *phoneTF = textFieldArray[3];
        if (textField == cardNoTF) {
            if ([textField.text isEqualToString:@""]) {
                return true;
            } else if (![ValidateUtils validateIDCardNumber:textField.text]) {
                [MBProgressHUD showTipMessageInWindow:@"身份证输入有误"];
                textField.text = @"";
            } else {
                //截取身份证中出行人出生日期中的年、月、日
                NSString *personYear = [textField.text substringWithRange:NSMakeRange(6, 4)];
                NSString *personMonth = [textField.text substringWithRange:NSMakeRange(10, 2)];
                NSString *personDay = [textField.text substringWithRange:NSMakeRange(12, 2)];
                NSMutableString *birthdayString = [[NSMutableString alloc] initWithString:personYear];
                [birthdayString appendFormat:@"-%@",personMonth];
                [birthdayString appendFormat:@"-%@",personDay];
                self.birthdayTF.text = birthdayString;
                //获取身份证号中的性别
                NSInteger gender = [ValidateUtils getGenderFromIdCard:textField.text];
                if (gender == 2) {//女
                    sexTF.text = @"女";
                } else {
                    sexTF.text = @"男";
                }
            }
        }
        if (textField == phoneTF) {
            if ([textField.text isEqualToString:@""]) {
                return true;
            } else if (![ValidateUtils validateMobile:phoneTF.text]) {
                [MBProgressHUD showTipMessageInWindow:@"老人家庭联系电话格式错误"];
                textField.text = @"";
            }
        }
    }
    return true;
}

//设置文本框只能输入数字
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (string.length == 0 ||  [string isEqualToString:@""]) return true;// 如果是删除字符，肯定是要通过的
    //如果是限制只能输入数字的文本框
    if (textField == self.cardNoTF) {
        if (![self validateIDCardNumber:string]) {
            return false;
        }
    }
    for (NSArray *textFieldArray in self.OldPeopleFamilyDataTFsArrayM) {
        UITextField *cardNoTF = textFieldArray[1];
        if (textField == cardNoTF) {
            if (![self validateIDCardNumber:string]) {
                return false;
            }
        } else if (textField == textFieldArray[3]) {
            return [self validateNumber:string];
        } else if (textField == textFieldArray[0] && textField.text.length >= 20) {
            textField.text = [textField.text substringToIndex:20];
            return NO;
        }
    }
    if (textField == self.phoneTF || textField == self.bankCardnoTF || textField == self.medicalCardnoTF || textField == self.socialCardnoTF) {
        if (![self validateNumber:string]) {
            return false;
        }
    }
    if (textField == self.incomeConditonTF) {
        /*
         * 不能输入.0-9以外的字符。
         * 设置输入框输入的内容格式
         * 只能有一个小数点
         * 小数点后最多能输入两位
         * 如果第一位是.则前面加上0.
         * 如果第一位是0则后面必须输入点，否则不能输入。
         */
        
        // 判断是否有小数点
        if ([textField.text containsString:@"."]) {
            self.isHaveDian = YES;
        }else{
            self.isHaveDian = NO;
        }
        if (string.length > 0) {
            //当前输入的字符
            unichar single = [string characterAtIndex:0];
            // 不能输入.0-9以外的字符
            if (!((single >= '0' && single <= '9') || single == '.'))
            {
                //            [MBProgressHUD bwm_showTitle:@"您的输入格式不正确" toView:self hideAfter:1.0];
                return NO;
            }
            
            // 只能有一个小数点
            if (self.isHaveDian && single == '.') {
                //            [MBProgressHUD bwm_showTitle:@"最多只能输入一个小数点" toView:self hideAfter:1.0];
                return NO;
            }
            
            // 如果第一位是.则前面加上0.
            if ((textField.text.length == 0) && (single == '.')) {
                textField.text = @"0";
            }
            
            // 如果第一位是0则后面必须输入点，否则不能输入。
            if ([textField.text hasPrefix:@"0"]) {
                if (textField.text.length > 2) {
                    NSString *secondStr = [textField.text substringWithRange:NSMakeRange(1, 1)];
                    if (![secondStr isEqualToString:@"."]) {
                        //                    [MBProgressHUD bwm_showTitle:@"第二个字符需要是小数点" toView:self hideAfter:1.0];
                        return NO;
                    }
                }else{
                    if (![string isEqualToString:@"."]) {
                        //                    [MBProgressHUD bwm_showTitle:@"第二个字符需要是小数点" toView:self hideAfter:1.0];
                        return NO;
                    }
                }
            }
            
            // 小数点后最多能输入两位
            if (self.isHaveDian) {
                NSRange ran = [textField.text rangeOfString:@"."];
                // 由于range.location是NSUInteger类型的，所以这里不能通过(range.location - ran.location)>2来判断
                if (range.location > ran.location) {
                    if ([textField.text pathExtension].length > 0) {
                        //                    [MBProgressHUD bwm_showTitle:@"小数点后最多有两位小数" toView:self hideAfter:1.0];
                        return NO;
                    }
                }
            }
        }
    }
    if (range.length == 1 && string.length == 0) {
        return YES;
    } else {
        //否则返回yes,不限制其他textfield
        if (textField == self.nameTF && textField.text.length >= 20) {
            textField.text = [textField.text substringToIndex:20];
            return NO;
        } else if (textField == self.cardNoTF && textField.text.length >= 18) {
            textField.text = [textField.text substringToIndex:18];
            return NO;
        } else if (textField == self.phoneTF && textField.text.length >= 11) {
            textField.text = [textField.text substringToIndex:11];
            return NO;
        } else if (textField == self.incomeConditonTF && textField.text.length >= 9) {
            textField.text = [textField.text substringToIndex:9];
            return NO;
        } else if (textField == self.bankCardnoTF && textField.text.length >= 20) {
            textField.text = [textField.text substringToIndex:20];
            return NO;
        } else if (textField == self.medicalCardnoTF && textField.text.length >= 20) {
            textField.text = [textField.text substringToIndex:20];
            return NO;
        } else if (textField == self.socialCardnoTF && textField.text.length >= 20) {
            textField.text = [textField.text substringToIndex:20];
            return NO;
        }
    }
    return YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    //判断加上输入的字符，是否超过界限  specialityTF  experienceTF
    NSString *str = [NSString stringWithFormat:@"%@%@", textView.text, text];
    NSInteger MaxLength = 0;
    if (textView == self.remarkTV) {
        MaxLength = 1000;
    } else {
        MaxLength = 80;
    }
    if (str.length > MaxLength) {
        NSRange rangeIndex = [str rangeOfComposedCharacterSequenceAtIndex:MaxLength];
        if (rangeIndex.length == 1) {//字数超限
            textView.text = [str substringToIndex:MaxLength];
        }else{
            NSRange rangeRange = [str rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MaxLength)];
            textView.text = [str substringWithRange:rangeRange];
        }
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView {
    for (int i = 0 ; i < self.OldPeopleFamilyDataTFsArrayM.count; i++) {
        NSArray *textFieldArray = self.OldPeopleFamilyDataTFsArrayM[i];
        NZKTextView *workUnitTV = textFieldArray[5];
        if (textView == workUnitTV && textView.text.length > 79) textView.text = [textView.text substringToIndex:80];
    }
    if ((textView == self.domicileAdrTV || textView == self.locationAdrTV) && textView.text.length > 79) textView.text = [textView.text substringToIndex:80];
    if (textView == self.remarkTV && textView.text.length > 999) textView.text = [textView.text substringToIndex:1000];
}

- (BOOL)validateNumber:(NSString*)number {
    BOOL res =YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i =0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i,1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length ==0) {
            res =NO;
            break;
        }
        i++;
    }
    return res;
}

- (BOOL)validateIDCardNumber:(NSString*)number {
    BOOL res =YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789Xx"];
    int i =0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i,1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length ==0) {
            res =NO;
            break;
        }
        i++;
    }
    return res;
}

- (NSArray *)sexTFArray {
    if (!_sexTFArray) {
        _sexTFArray = @[@"男",@"女",@"未知"];
    }
    return _sexTFArray;
}
- (NSArray *)nationTFArray {
    if (!_nationTFArray) {
        _nationTFArray = @[@"汉族", @"壮族", @"回族", @"苗族", @"维吾尔族", @"土家族", @"彝族", @"藏族", @"布依族", @"朝鲜族", @"蒙古族", @"满族",@"侗族", @"瑶族", @"白族", @"哈尼族", @"哈萨克族", @"黎族", @"傣族", @"畲族", @"傈僳族",@"仡佬族",@"东乡族", @"高山族", @"拉祜族", @"水族", @"佤族",  @"纳西族",@"羌族", @"土族",@"仫佬族", @"锡伯族", @"柯尔克孜族",@"达斡尔族",@"景颇族",@"毛南族",@"撒拉族", @"布朗族", @"塔吉克族", @"阿昌族", @"普米族",@"鄂温克族", @"怒族",@"京族",  @"基诺族",@"德昂族", @"保安族",@"俄罗斯族", @"裕固族",@"乌孜别克族", @"门巴族",@"鄂伦春族",@"独龙族", @"塔塔尔族", @"赫哲族",@"珞巴族"];
    }
    return _nationTFArray;
}
- (NSArray *)medicalTypeTFArray {
    if (!_medicalTypeTFArray) {
        _medicalTypeTFArray = @[@"职工医保",@"居民医保",@"新型农村合作医疗"];
    }
    return _medicalTypeTFArray;
}
- (NSArray *)bodyConditionTFArray {
    if (!_bodyConditionTFArray) {
        _bodyConditionTFArray = @[@"自理",@"半失能",@"失能"];
    }
    return _bodyConditionTFArray;
}
- (NSArray *)disablestandTFArray {
    if (!_disablestandTFArray) {
        _disablestandTFArray = @[@"无法吃饭",@"无法穿衣",@"无法上下床",@"无法上厕所",@"无法室内走动",@"无法洗澡"];
    }
    return _disablestandTFArray;
}
- (NSArray *)disablestand1TFArray {
    if (!_disablestand1TFArray) {
        _disablestand1TFArray = @[@"轻度失能",@"中度失能",@"重度失能"];
    }
    return _disablestand1TFArray;
}
- (NSArray *)serviceNeedsTFArray {
    if (!_serviceNeedsTFArray) {
        _serviceNeedsTFArray = @[@"运动健身",@"棋牌活动",@"书法绘画",@"唱歌跳舞",@"家人慰藉",@"谈心聊天",@"洗衣做饭",@"清洁卫生"];
    }
    return _serviceNeedsTFArray;
}
- (NSArray *)survivalstateTFArray {
    if (!_survivalstateTFArray) {
        _survivalstateTFArray = @[@"存活",@"死亡"];
    }
    return _survivalstateTFArray;
}
- (NSArray *)basicLivingTFArray {
    if (!_basicLivingTFArray) {
        _basicLivingTFArray = @[@"否",@"是"];
    }
    return _basicLivingTFArray;
}

- (NSArray *)emergencyContactTFArray {
    if (!_emergencyContactTFArray) {
        _emergencyContactTFArray = @[@"是",@"否"];
    }
    return _emergencyContactTFArray;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    sectionHeaderView.backgroundColor = hexColor(FFFFFF);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 44) andText:@"" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Bold" size:14] andTextAlignment:NSTextAlignmentCenter];
    if (section == 0) {
        titleLabel.text = @"老人基础信息";
    } else {
        titleLabel.text = [NSString stringWithFormat:@"老人家庭信息%ld",(long)section];
    }
    [sectionHeaderView addSubview:titleLabel];
    if (!self.isCheck) {
        if (section > 0) {
            UIButton *sectionAddButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-15-50, 8, 50, 28)];
            [sectionAddButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
            sectionAddButton.layer.cornerRadius = 4;
            sectionAddButton.layer.masksToBounds = true;
            sectionAddButton.backgroundColor = NAV_COLOR;
            sectionAddButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
            [sectionAddButton addTarget:self action:@selector(sectionAddButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            [sectionAddButton setTitle:@"增加" forState:UIControlStateNormal];
            [sectionHeaderView addSubview:sectionAddButton];
            if (self.OldPeopleFamilyDataCount > 0) {
                UIButton *sectionDeleteButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-15-50-15-50, 8, 50, 28)];
                [sectionDeleteButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
                sectionDeleteButton.layer.cornerRadius = 4;
                sectionDeleteButton.layer.masksToBounds = true;
                sectionDeleteButton.backgroundColor = NAV_COLOR;
                sectionDeleteButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
                [sectionDeleteButton addTarget:self action:@selector(sectionDeleteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
                [sectionDeleteButton setTitle:@"删除" forState:UIControlStateNormal];
                [sectionHeaderView addSubview:sectionDeleteButton];
            }
        }
    }
    return sectionHeaderView;
}

- (void)sectionAddButtonClick:(UIButton *)sectionAddButton {
    [self addOneSectionOfTextFields];
    self.OldPeopleFamilyDataCount++;
    [self.tableView reloadData];
}
- (void)sectionDeleteButtonClick:(UIButton *)sectionDeleteButton {
    if (self.OldPeopleFamilyDataCount > 0) {
        self.OldPeopleFamilyDataCount--;
        [self.OldPeopleFamilyDataTFsArrayM removeLastObject];
    }
    [self.tableView reloadData];
}

- (void)addOneSectionOfTextFields {
    UITextField *nameTF = [[UITextField alloc] init];
    nameTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
    nameTF.delegate = self;
    
    UITextField *sexTF = [[UITextField alloc] init];
    sexTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
//    UIImageView *sexTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
//    sexTFRightViewImageView.contentMode = UIViewContentModeCenter;
//    sexTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
//    sexTF.rightView = sexTFRightViewImageView;
//    sexTF.rightViewMode = UITextFieldViewModeAlways;
    sexTF.delegate = self;
    
    UITextField *phoneTF = [[UITextField alloc] init];
    phoneTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
    phoneTF.keyboardType = UIKeyboardTypePhonePad;
    phoneTF.delegate = self;
    
    UITextField *cardNoTF = [[UITextField alloc] init];
    cardNoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
//    cardNoTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    cardNoTF.delegate = self;
    
    UITextField *relationTF = [[UITextField alloc] init];
    relationTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
    relationTF.delegate = self;

    NZKTextView *wordUnitTV = [[NZKTextView alloc] init];
    wordUnitTV.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
    wordUnitTV.delegate = self;
    //内容缩进为0（去除左右边距）
    wordUnitTV.textContainer.lineFragmentPadding = 0;
    //文本边距设为0（去除上下边距）
    wordUnitTV.textContainerInset = UIEdgeInsetsMake(10, 0, 8, 0);
    wordUnitTV.placeHolder = @"限制在80字以内";
    
    UITextField *ifUrgencyLinkmanTF = [[UITextField alloc] init];
    ifUrgencyLinkmanTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
    ifUrgencyLinkmanTF.delegate = self;
    [self.OldPeopleFamilyDataTFsArrayM addObject:@[nameTF,cardNoTF,sexTF,phoneTF,relationTF,wordUnitTV,ifUrgencyLinkmanTF]];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight)];
        _tableView.separatorInset = UIEdgeInsetsZero;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = hexColor(EEEEEE);
        if (!self.isCheck) {
            _tableView.tableFooterView = self.tableViewFooterView;
        }
        [_tableView registerClass:LSInfoCollectTableViewCell.class forCellReuseIdentifier:OldPeopleFoundationDataCollectCellID];
    }
    return _tableView;
}

- (UIView *)tableViewFooterView {
    if (!_tableViewFooterView) {
        _tableViewFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
        UIButton *submitButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 30, ScreenWidth-30, 40)];
        [submitButton setTitle:@"提交" forState:UIControlStateNormal];
        [submitButton setTitleColor:hexColor(ffffff) forState:UIControlStateNormal];
        submitButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
        submitButton.backgroundColor = hexColor(FDBB2C);
        submitButton.layer.cornerRadius = 4;
        submitButton.layer.masksToBounds = true;
        [submitButton addTarget:self action:@selector(submitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [_tableViewFooterView addSubview:submitButton];
    }
    return _tableViewFooterView;
}

- (NSArray *)contentArray {
    if (!_contentArray) {
        _contentArray = @[@"姓名：",@"身份证号：",@"出生日期：",@"性别：",@"民族：",@"原户籍地：",@"原户籍地详细地址：",@"现住地：",@"现住地详细地址：",@"联系电话：",@"收入状况(元/月)：",@"银行卡号：",@"医保类型：",@"医疗卡号：",@"社保账号：",@"身体状况：",@"服务需求：",@"存活状态：",@"是否低保：",@"备注："];
    }
    return _contentArray;
}
- (NSArray *)contentArray_isShiNeng {
    if (!_contentArray_isShiNeng) {
        _contentArray_isShiNeng = @[@"姓名：",@"身份证号：",@"出生日期：",@"性别：",@"民族：",@"原户籍地：",@"原户籍地详细地址：",@"现住地：",@"现住地详细地址：",@"联系电话：",@"收入状况(元/月)：",@"银行卡号：",@"医保类型：",@"医疗卡号：",@"社保账号：",@"身体状况：",@"失能标准：",@"失能等级：",@"服务需求：",@"存活状态：",@"是否低保：",@"备注："];
    }
    return _contentArray_isShiNeng;
}

- (NSArray *)familyinfoEntitiesContentArray {
    if (!_familyinfoEntitiesContentArray) {
        _familyinfoEntitiesContentArray = @[@"姓名：",@"身份证号：",@"性别：",@"联系电话：",@"关系：",@"工作单位：",@"是否紧急联系人："];
    }
    return _familyinfoEntitiesContentArray;
}

- (NSArray *)relationTFArray {
    if (!_relationTFArray) {
        _relationTFArray = @[@"本人或者户主",@"配偶",@"子或婿",@"女或媳",@"孙子女或外孙子女",@"父母或岳父母或公婆",@"祖父母或外祖父母",@"兄弟姐妹",@"其他"];
    }
    return _relationTFArray;
}

- (NSMutableArray *)OldPeopleFamilyDataArrayM {
    if (!_OldPeopleFamilyDataArrayM) {
        _OldPeopleFamilyDataArrayM = [[NSMutableArray alloc] init];
    }
    return _OldPeopleFamilyDataArrayM;
}

- (NSMutableArray *)OldPeopleFamilyDataTFsArrayM {
    if (!_OldPeopleFamilyDataTFsArrayM) {
        _OldPeopleFamilyDataTFsArrayM = [[NSMutableArray alloc] init];
    }
    return _OldPeopleFamilyDataTFsArrayM;
}

#pragma mark - 老龄人基本信息控件
- (UITextField *)nameTF {
    if (!_nameTF) {
        _nameTF = [[UITextField alloc] init];
        _nameTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _nameTF.delegate = self;
    }
    return _nameTF;
}
- (UITextField *)cardNoTF {
    if (!_cardNoTF) {
        _cardNoTF = [[UITextField alloc] init];
        _cardNoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _cardNoTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _cardNoTF.delegate = self;
    }
    return _cardNoTF;
}
- (UITextField *)sexTF {
    if (!_sexTF) {
        _sexTF = [[UITextField alloc] init];
        _sexTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
//        if (!self.isCheck) {
//            UIImageView *sexTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
//            sexTFRightViewImageView.contentMode = UIViewContentModeCenter;
//            sexTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
//            _sexTF.rightView = sexTFRightViewImageView;
//            _sexTF.rightViewMode = UITextFieldViewModeAlways;
//        }
        _sexTF.delegate = self;
    }
    return _sexTF;
}
- (UITextField *)birthdayTF {
    if (!_birthdayTF) {
        _birthdayTF = [[UITextField alloc] init];
        _birthdayTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
//        if (!self.isCheck) {
//            UIImageView *birthdayTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
//            birthdayTFRightViewImageView.contentMode = UIViewContentModeCenter;
//            birthdayTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
//            _birthdayTF.rightView = birthdayTFRightViewImageView;
//            _birthdayTF.rightViewMode = UITextFieldViewModeAlways;
//        }
        _birthdayTF.delegate = self;
    }
    return _birthdayTF;
}
- (UITextField *)nationTF {
    if (!_nationTF) {
        _nationTF = [[UITextField alloc] init];
        _nationTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *nationTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            nationTFRightViewImageView.contentMode = UIViewContentModeCenter;
            nationTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _nationTF.rightView = nationTFRightViewImageView;
            _nationTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _nationTF.delegate = self;
    }
    return _nationTF;
}
- (UITextField *)regAdTF {
    if (!_regAdTF) {
        _regAdTF = [[UITextField alloc] init];
        _regAdTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *regAdTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            regAdTFRightViewImageView.contentMode = UIViewContentModeCenter;
            regAdTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _regAdTF.rightView = regAdTFRightViewImageView;
            _regAdTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _regAdTF.delegate = self;
    }
    return _regAdTF;
}
- (NZKTextView *)domicileAdrTV {
    if (!_domicileAdrTV) {
        _domicileAdrTV = [[NZKTextView alloc] init];
        _domicileAdrTV.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _domicileAdrTV.delegate = self;
        //内容缩进为0（去除左右边距）
        _domicileAdrTV.textContainer.lineFragmentPadding = 0;
        //文本边距设为0（去除上下边距）
        _domicileAdrTV.textContainerInset = UIEdgeInsetsMake(10, 0, 8, 0);
        _domicileAdrTV.placeHolder = @"限制在80字以内";
    }
    return _domicileAdrTV;
}
- (UITextField *)nowAdTF {
    if (!_nowAdTF) {
        _nowAdTF = [[UITextField alloc] init];
        _nowAdTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *nowAdTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            nowAdTFRightViewImageView.contentMode = UIViewContentModeCenter;
            nowAdTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _nowAdTF.rightView = nowAdTFRightViewImageView;
            _nowAdTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _nowAdTF.delegate = self;
    }
    return _nowAdTF;
}
- (NZKTextView *)locationAdrTV {
    if (!_locationAdrTV) {
        _locationAdrTV = [[NZKTextView alloc] init];
        _locationAdrTV.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _locationAdrTV.delegate = self;
        //内容缩进为0（去除左右边距）
        _locationAdrTV.textContainer.lineFragmentPadding = 0;
        //文本边距设为0（去除上下边距）
        _locationAdrTV.textContainerInset = UIEdgeInsetsMake(10, 0, 8, 0);
        _locationAdrTV.placeHolder = @"限制在80字以内";
    }
    return _locationAdrTV;
}
- (UITextField *)phoneTF {
    if (!_phoneTF) {
        _phoneTF = [[UITextField alloc] init];
        _phoneTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _phoneTF.keyboardType = UIKeyboardTypePhonePad;
        _phoneTF.delegate = self;
    }
    return _phoneTF;
}
- (UITextField *)incomeConditonTF {
    if (!_incomeConditonTF) {
        _incomeConditonTF = [[UITextField alloc] init];
        _incomeConditonTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _incomeConditonTF.keyboardType = UIKeyboardTypeNumberPad;
        _incomeConditonTF.delegate = self;
    }
    return _incomeConditonTF;
}
- (UITextField *)bankCardnoTF {
    if (!_bankCardnoTF) {
        _bankCardnoTF = [[UITextField alloc] init];
        _bankCardnoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _bankCardnoTF.keyboardType = UIKeyboardTypeNumberPad;
        _bankCardnoTF.delegate = self;
    }
    return _bankCardnoTF;
}
- (UITextField *)medicalTypeTF {
    if (!_medicalTypeTF) {
        _medicalTypeTF = [[UITextField alloc] init];
        _medicalTypeTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *medicalTypeTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            medicalTypeTFRightViewImageView.contentMode = UIViewContentModeCenter;
            medicalTypeTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _medicalTypeTF.rightView = medicalTypeTFRightViewImageView;
            _medicalTypeTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _medicalTypeTF.delegate = self;
    }
    return _medicalTypeTF;
}
- (UITextField *)medicalCardnoTF {
    if (!_medicalCardnoTF) {
        _medicalCardnoTF = [[UITextField alloc] init];
        _medicalCardnoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _medicalCardnoTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _medicalCardnoTF.delegate = self;
    }
    return _medicalCardnoTF;
}
- (UITextField *)socialCardnoTF {
    if (!_socialCardnoTF) {
        _socialCardnoTF = [[UITextField alloc] init];
        _socialCardnoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _socialCardnoTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _socialCardnoTF.delegate = self;
    }
    return _socialCardnoTF;
}
- (UITextField *)bodyConditionTF {
    if (!_bodyConditionTF) {
        _bodyConditionTF = [[UITextField alloc] init];
        _bodyConditionTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *bodyConditionTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            bodyConditionTFRightViewImageView.contentMode = UIViewContentModeCenter;
            bodyConditionTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _bodyConditionTF.rightView = bodyConditionTFRightViewImageView;
            _bodyConditionTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _bodyConditionTF.delegate = self;
    }
    return _bodyConditionTF;
}
- (UITextField *)disablestandTF {
    if (!_disablestandTF) {
        _disablestandTF = [[UITextField alloc] init];
        _disablestandTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *disablestandTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            disablestandTFRightViewImageView.contentMode = UIViewContentModeCenter;
            disablestandTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _disablestandTF.rightView = disablestandTFRightViewImageView;
            _disablestandTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _disablestandTF.delegate = self;
    }
    return _disablestandTF;
}
- (UITextField *)disablestand1TF {
    if (!_disablestand1TF) {
        _disablestand1TF = [[UITextField alloc] init];
        _disablestand1TF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
//        if (!self.isCheck) {
//            UIImageView *disablestand1TFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
//            disablestand1TFRightViewImageView.contentMode = UIViewContentModeCenter;
//            disablestand1TFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
//            _disablestand1TF.rightView = disablestand1TFRightViewImageView;
//            _disablestand1TF.rightViewMode = UITextFieldViewModeAlways;
//        }
        _disablestand1TF.delegate = self;
    }
    return _disablestand1TF;
}
- (UITextField *)serviceNeedsTF {
    if (!_serviceNeedsTF) {
        _serviceNeedsTF = [[UITextField alloc] init];
        _serviceNeedsTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *serviceNeedsTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            serviceNeedsTFRightViewImageView.contentMode = UIViewContentModeCenter;
            serviceNeedsTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _serviceNeedsTF.rightView = serviceNeedsTFRightViewImageView;
            _serviceNeedsTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _serviceNeedsTF.delegate = self;
    }
    return _serviceNeedsTF;
}
- (UITextField *)survivalstateTF {
    if (!_survivalstateTF) {
        _survivalstateTF = [[UITextField alloc] init];
        _survivalstateTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *survivalstateTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            survivalstateTFRightViewImageView.contentMode = UIViewContentModeCenter;
            survivalstateTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _survivalstateTF.rightView = survivalstateTFRightViewImageView;
            _survivalstateTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _survivalstateTF.delegate = self;
    }
    return _survivalstateTF;
}
- (UITextField *)basicLivingTF {
    if (!_basicLivingTF) {
        _basicLivingTF = [[UITextField alloc] init];
        _basicLivingTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        if (!self.isCheck) {
            UIImageView *basicLivingTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
            basicLivingTFRightViewImageView.contentMode = UIViewContentModeCenter;
            basicLivingTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
            _basicLivingTF.rightView = basicLivingTFRightViewImageView;
            _basicLivingTF.rightViewMode = UITextFieldViewModeAlways;
        }
        _basicLivingTF.delegate = self;
    }
    return _basicLivingTF;
}
- (NZKTextView *)remarkTV {
    if (!_remarkTV) {
        _remarkTV = [[NZKTextView alloc] init];
        _remarkTV.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _remarkTV.delegate = self;
        //内容缩进为0（去除左右边距）
        _remarkTV.textContainer.lineFragmentPadding = 0;
        //文本边距设为0（去除上下边距）
        _remarkTV.textContainerInset = UIEdgeInsetsMake(10, 0, 8, 0);
        _remarkTV.placeHolder = @"限制在1000字以内";
    }
    return _remarkTV;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
